package com.ruoyi.video.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.video.domain.VideoNvr;
import com.ruoyi.video.service.IVideoNvrService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * NVRController
 * 
 * @author ruoyi
 * @date 2024-12-09
 */
@RestController
@RequestMapping("/video/nvr")
public class VideoNvrController extends BaseController
{
    @Autowired
    private IVideoNvrService videoNvrService;

    /**
     * 查询NVR列表
     */
    @PreAuthorize("@ss.hasPermi('video:nvr:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoNvr videoNvr)
    {
        startPage();
        List<VideoNvr> list = videoNvrService.selectVideoNvrList(videoNvr);
        return getDataTable(list);
    }

    /**
     * 导出NVR列表
     */
    @PreAuthorize("@ss.hasPermi('video:nvr:export')")
    @Log(title = "NVR", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VideoNvr videoNvr)
    {
        List<VideoNvr> list = videoNvrService.selectVideoNvrList(videoNvr);
        ExcelUtil<VideoNvr> util = new ExcelUtil<VideoNvr>(VideoNvr.class);
        util.exportExcel(response, list, "NVR数据");
    }

    /**
     * 获取NVR详细信息
     */
    @PreAuthorize("@ss.hasPermi('video:nvr:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(videoNvrService.selectVideoNvrById(id));
    }

    /**
     * 新增NVR
     */
    @PreAuthorize("@ss.hasPermi('video:nvr:add')")
    @Log(title = "NVR", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoNvr videoNvr)
    {
        videoNvr.setCreateBy(getUsername());
        return toAjax(videoNvrService.insertVideoNvr(videoNvr));
    }

    /**
     * 修改NVR
     */
    @PreAuthorize("@ss.hasPermi('video:nvr:edit')")
    @Log(title = "NVR", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoNvr videoNvr)
    {
        videoNvr.setUpdateBy(getUsername());
        return toAjax(videoNvrService.updateVideoNvr(videoNvr));
    }

    /**
     * 删除NVR
     */
    @PreAuthorize("@ss.hasPermi('video:nvr:remove')")
    @Log(title = "NVR", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(videoNvrService.deleteVideoNvrByIds(ids));
    }
}
